
package com.idealighter.game.dictionary.dic;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.dictionary.core.DictionaryTable;
import com.idealighter.game.dictionary.domain.SharkIconPlanDomain;
import com.idealighter.game.dictionary.mapper.SharkIconPlanMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Singleton
public class SharkIconPlanDic implements DictionaryTable<SharkIconPlanDomain> {

  private SharkIconPlanMapper mapper;
  private List<SharkIconPlanDomain> list;
  private Map<Integer, SharkIconPlanDomain> map;

  // 合计概率
  private int totalProbability;

  @Inject
  public SharkIconPlanDic(SharkIconPlanMapper mapper) {
    this.mapper = mapper;
    load();
  }

  @Override
  public List<SharkIconPlanDomain> list() {

    return list;
  }

  @Override
  public Map<Integer, SharkIconPlanDomain> map() {

    return map;
  }

  @Override
  public void load() {
    this.list = mapper.selectAll();
    this.totalProbability = 0;
    Map<Integer, SharkIconPlanDomain> map = new HashMap<>();
    list.forEach(val -> {
      map.put(val.getId(), val);
      this.totalProbability += val.getProbability();
    });
    this.map = map;
  }

  @Override
  public SharkIconPlanDomain get(int id) {

    return map.get(id);
  }

  public int getTotalProbability() {
    return totalProbability;
  }

}
